﻿using soma.Models.Resources;
using soma.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace soma.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            APIKeyVerifier.Instance.LoadXDocument(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data"), "keys.xml"));
        //    TwitterSearch twitterSearch = new TwitterSearch();

            /*
            FlickrSearch flickrSearch = new FlickrSearch();
            List<PhotoResource> photoResourceList = new List<PhotoResource>(); //flickrSearch.SearchPhotosByTag("blue", DateTime.Now.AddDays(-2));

            PhotosRepository pr = PhotosRepository.Instance;

       //     List<PhotoResource> photos = pr.GetPhotosByTag("cat");
            List<string> ph = new List<string>();
            
            // {0} - resource url
            // {1} - photo src - default "assets/img/property-tmp-small.png"
            // {2} - photo alt;
            // {3} - title
            // {4} - website
            

            foreach (PhotoResource photoRes in photos)
            {
                var property3 = "<div class=\"infobox clearfix\">" +
                            "<div class=\"info\">" +
                                "<div class=\"title\">" +
                                    "<a href=\"" + photoRes.Url + "\">" + photoRes.Url + "</a></div></div></div>";


                // {0} - resource url
                // {1} - photo src - default "assets/img/property-tmp-small.png"
                // {2} - photo alt;
                // {3} - title
                // {4} - website

                string res = string.Format(Helpers.StringDivs.PhotoDivFormat, photoRes.Url, "assets/img/property-tmp-small.png", 
                    photoRes.PhotoName, photoRes.PhotoName, photoRes.Website);
                res = res.Replace("\n", "");
                res = res.Replace("\t", "");
                res = res.Replace("\r", "");
                ph.Add(res);
            }
            */
            
            

            return View();
        }

        public ActionResult Filter()
        {
      /*      HttpWebRequest httpWebRequest = WebRequest.Create("http://localhost:11882/api/resources/photos/cat?key=lro2e32") as HttpWebRequest;
            WebResponse webResponse = httpWebRequest.GetResponse();

            PhotosRepository pr = PhotosRepository.Instance;

            List<PhotoResource> photos = pr.GetPhotosByTag("cat");
            List<string> ph = new List<string>();

            // {0} - resource url
            // {1} - photo src - default "assets/img/property-tmp-small.png"
            // {2} - photo alt;
            // {3} - title
            // {4} - website
            string resourceFormat= 
                @"<div class=""infobox clearfix"">
	                <div class=""close"">
		                <img src=""assets/img/close.png"">
	                </div>
	                <div class=""image"">
		                <a href = ""{0}"" >
			                <img src=""{1}"" alt=""{2}"" width=""130px"">
		                </a>
	                </div>
	                <div class=""info"">
		                <div class=""title"">
			                <a href=""{0}"">{3}</a>
		                </div>
		                <div class=""location"">{4}/div>
		                
		                <div class=""link"">
			                <a href=""{0}"">View more</a>
		                </div>
	                </div>
                    </div>";

            foreach (PhotoResource photoRes in photos)
            {
                var property3 = "<div class=\"infobox clearfix\">" +
                            "<div class=\"info\">" +
                                "<div class=\"title\">" +
                                    "<a href=\"" + photoRes.Url + "\">" + photoRes.Url + "</a></div></div></div>";

               
                // {0} - resource url
                // {1} - photo src - default "assets/img/property-tmp-small.png"
                // {2} - photo alt;
                // {3} - title
                // {4} - website

                string.Format(resourceFormat, photoRes.Url, "assets/img/property-tmp-small.png", photoRes.PhotoName, photoRes.PhotoName, photoRes.Website);
                ph.Add(resourceFormat);
            }*/
            return View();
        }
    }
}
